﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Assertions;

public enum CameraMode {
    CM_Normal = 0,
    CM_Tank,
}

public class CameraMgr {

    private static CameraMgr _instance = null;
    public static CameraMgr instance {
        get {
            if (_instance == null) {
                _instance = new CameraMgr();
                _instance.Init();
            }
            return _instance;
        }
    }

    private List<CameraBase> _cameraList = null;
    private CameraMode _cameraActivityMode;
    public void Init() {
        GameObject cameraObj = GameObject.Find("MainCamera");
        _cameraList = new List<CameraBase>();
        _cameraList.Add(cameraObj.GetComponent<CameraNormal>());
        _cameraList.Add(cameraObj.GetComponent<CameraTank>());

        _cameraActivityMode = CameraMode.CM_Normal;
        CameraActivityReset();
    }

    public CameraBase getCameraActivity() {
        uint cameraIdx = (uint)_cameraActivityMode;
        if ( cameraIdx >= _cameraList.Count ){
            Assert.IsFalse( true, "Camera Activity Error");
        }
        
        return _cameraList[(int)cameraIdx];
    }

    public void Tick() {
        getCameraActivity().Tick();
    }

    public void CameraChangeNext() {
        int count = _cameraList.Count;
        if (count <= 1)
            return;

        int mode = (int)_cameraActivityMode;
        _cameraActivityMode = (CameraMode)(++mode % count);
        CameraActivityReset();
    }

    public void CameraActivityReset() {
        getCameraActivity().Reset();
    }


}
